<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserWeeklyStatsTable extends Migration
{
    protected $tableName = 'user_weekly_stats';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create($this->tableName, function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id')->comment('用户ID');
            $table->unsignedInteger('week')->comment('周数');
            $table->unsignedInteger('word_count')->comment('单词数');
            $table->date('start_data')->comment('本周开始日期');
            $table->date('end_data')->comment('本周结束日期');

            $table->timestamps();
            $table->softDeletes();

            $table->index(['user_id', 'week'], 'user_week');
        });
        DB::statement("ALTER TABLE `$this->tableName` comment '用户学习周报'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->tableName);
    }
}
